/**
 * 
 */
package com.scpii.universal.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.googlecode.ehcache.annotations.TriggersRemove;
import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.ClientMoreDto;
import com.scpii.universal.hibernate.dao.AppPageViewDao;
import com.scpii.universal.hibernate.dao.MoreContentDao;
import com.scpii.universal.hibernate.entity.MoreContentTab;
import com.scpii.universal.service.MoreContentService;

/**
 * genericWeb
 * @author weny
 * 2012-7-8下午09:46:20
 */
@Service
public class MoreContentServiceImpl extends BaseServiceImpl<MoreContentTab, Integer> implements
		MoreContentService {

	@Resource
	private MoreContentDao moreContentDao;
	@Resource
	private AppPageViewDao appPageViewDao;

	public void setBaseDao(MoreContentDao moreContentDao) {
		super.setBaseDao(moreContentDao);
	}

	@Override
	@TriggersRemove(cacheName=GenericConstants.CATELOG_EHCACHE,removeAll=true)
	public void delete(Integer id) {
		moreContentDao.delete(id);
	}

	@Override
	@TriggersRemove(cacheName=GenericConstants.CATELOG_EHCACHE,removeAll=true)
	public void deleteView(int viewId) {
		//删除视图
		appPageViewDao.delete(viewId);
		//删除视图里绑定的内容
		StringBuffer hql = new StringBuffer("update MoreContentTab m set ");
		hql.append("m.intDeleteSign=:intDeleteSign");
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_DELETED);
		hql.append(" where m.intViewId=:intViewId");
		argsMap.put("intViewId", viewId);
		moreContentDao.hqlOperation(hql.toString(), argsMap);
	}

	@Override
	public List<ClientMoreDto> listMoreContentByCon(int appId, int type) {
		return moreContentDao.listMoreContentByCon(appId, type);
	}

	@Override
	public void updateMoreContent(int id, String content) {
		StringBuffer hql = new StringBuffer("update MoreContentTab m set ");
		hql.append("m.varMoreContent=:varMoreContent");
		hql.append(",m.datUpdateDatetime=:datUpdateDatetime");
		hql.append(" where m.intMoreContent=:intMoreContent");
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("varMoreContent", content);
		argsMap.put("datUpdateDatetime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		argsMap.put("intMoreContent", id);
		moreContentDao.hqlOperation(hql.toString(), argsMap);
	}

}
